package com.ant.test;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Created by baichuan on 2016/12/1.
 */
public class UserTest01 {


    @Test
    public void test001() throws SQLException {

        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicatonContext.xml");
        ComboPooledDataSource data = (ComboPooledDataSource) context.getBean("dataSource");
        Connection conn = data.getConnection();
        Statement stat = conn.createStatement();
        String sql = "SELECT * from duser1";
        ResultSet resultSet = stat.executeQuery(sql);
        while (resultSet.next()) {
            System.out.print(resultSet.getInt("id") + "\t");
            System.out.print(resultSet.getString("name") + "\t");
            System.out.print(resultSet.getString("password") + "\t\n");
        }
        stat.close();
        conn.close();
        System.out.println(data == null);

    }
}
